/*
 * @(#)SdeReader.java $version 2012. 5. 31.
 *
 */

package com.mywep.myalimi.batch.sde;

import java.util.Calendar;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mywep.myalimi.common.DbConditionHolder;
import com.mywep.myalimi.model.NewContent;
import com.mywep.myalimi.repository.content.NewContentRepository;

import com.nhncorp.lucy.spring.core.util.ExtendedMap;

/**
 * @author 한지웅
 */
@Component
public class SdeReader implements ItemReader<List<NewContent>> {
	@Autowired
	private NewContentRepository newContentRepository;
	/**
	 * @return
	 * @throws Exception
	 * @throws UnexpectedInputException
	 * @throws ParseException
	 * @throws NonTransientResourceException
	 * @see org.springframework.batch.item.ItemReader#read()
	 */
	@Override
	public List<NewContent> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.HOUR, -8);
		ExtendedMap param = DbConditionHolder.getInstance();
		param.put("greateThanInsertDate", calendar.getTime());
		List<NewContent> newContentList = newContentRepository.selectByExample(param);
		if (CollectionUtils.isEmpty(newContentList)) {
			return null;
		}

		return newContentList;
	}

}
